package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.domain.Sort;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    //@Insert("insert into orders (number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, remark, phone, address, user_name, consignee, cancel_reason, rejection_reason, cancel_time, estimated_delivery_time, delivery_status, delivery_time, pack_amount, tableware_number, tableware_status) values" +
      //      " (#{number},#{status},#{userId},#{addressBookId},#{orderTime},#{checkoutTime},#{payMethod},#{payStatus},#{amount},#{remark},#{phone},#{address},#{userName},#{consignee},#{cancelReason},#{cancelTime},#{estimatedDeliveryTime},#{deliveryStatus},#{deliveryTime},#{packAmount},#{tablewareNumber},#{tablewareStatus})")
    void insertOrders(Orders orders);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    @Select("select * from orders where status=#{status} and order_time < #{localDateTime};")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime localDateTime);


    //动态查询历史订单  //查询用户所有订单
    Page<Orders> selectOrderPage(OrdersPageQueryDTO ordersPageQueryDTO);


    Orders selectOrderByOrderIdAndUserId(Long userId, Long orderId);

    @Select("select * from orders where id=#{id};")
    Orders getById(Long id);
    //@Select("select sum(amount) from orders where order_time>#{begin} and order_time<#{end} and status=#{status};")
    Double getTurnOver(Map map);

    //动态的查询每天的订单数(总数/有效订单数)
    Integer getCountByMap(Map map);


    List<GoodsSalesDTO> getSalesTop10(LocalDateTime beginTime, LocalDateTime endTime);

    Integer getCountStatusEver(Integer status);
}
